<?php
/*
后台活动控制器
*/

Class Weixin_Actioninfo_module extends CI_Module
{
	public $setting;
	public $aid;
	public $sid;
	public $adminid;
	
	public function __construct()
    {
        parent::__construct();
		$this->sid = $GLOBALS['sid'];
		$this->load->model('weixin.weixin_model');
        $this->load->model('expert.Expert_model');
		$this->load->library("pagination");
        $this->setting = $this->weixin_model->db_get_setting();
        define('TOKEN', @$this->setting['token']);
        define('APPID', @$this->setting['appid']);
        define('APPSECRET', @$this->setting['appsecret']);
        $this->adminid = $this->session->userdata('admin_user_id');
        if (!$this->adminid) {
            redirect(site_url('admin/index/login'));
        }		
		$id=$this->uri->segment(4,0);
		$this->aid=$id?$id:1;
        $this->load->model('weixin.actioninfo_model');					//载入模型
    }
	
	function index($id=""){
		$pagenum=15;
		$allnum=$this->actioninfo_model->num_activ($this->sid);
		/*
		$config['total_rows']=$allnum;   		//CI配置文件 总共的条数
		$config['per_page']=$pagenum;			//CI配置文件，一页显示条数
		$config['num_links']=4;					//当前页前后要显示的几个分页连接
		$config['base_url']=site_url("/weixin/actioninfo/index");
		$config['use_page_numbers']=true;
		
		//调用分类页
		$this->pagination->initialize($config);
		$activlist['pagelists']=$this->pagination->create_links()."<br/>";
		*/


		$config['uri_segment'] = 4;
		$config['total_rows']=$allnum;   		//CI配置文件 总共的条数
		$config['per_page']=$pagenum;			//CI配置文件，一页显示条数
		$config['num_links']=3;					//当前页前后要显示的几个分页连接

		$config['base_url']=site_url("/weixin/actioninfo/index");
		$config['use_page_numbers']=true;
		$config['first_link'] = '第一页';
		$config['last_link'] = '最后一页';
		//调用分类页
		$this->pagination->initialize($config);
		$activlist['pagelists']=$this->pagination->create_links()."<br/>";

		$id=$id?$id:1;
		$startpage=($id-1)*$pagenum;			//第几页从第几条开始显示
		$activlist['list']=$this->actioninfo_model->sel_activ_page($startpage,$pagenum,$this->sid); //倒叙排列
		$activlist['title']='活动管理';
		$activlist['view']="action/actioninfo_manage_view";
				
		$this->loadview($activlist, 'xenon/common/index');
	}
	
	//显示添加页面
	function add_view(){		
		//$activadd['index_url']="weixin/actioninfo/insert_add";
		$activadd['view']="action/actioninfo_manage_add_view";
		$this->loadview($activadd,'xenon/common/index');
	}
	//添加记录
	function insert_add(){		
		$htmlData = '';
	if (!empty($_POST['content1'])) {
		if (get_magic_quotes_gpc()) {
			$htmlData = stripslashes($_POST['content1']);
		} else {
			$htmlData = $_POST['content1'];
		}
	}	
		$val=array(
			"sid"=>$this->sid,
			"addid"=>$this->adminid,
			"aname"=>$_POST['actxt'],
			"aword"=>$_POST['tkword'],
			"acont"=>$htmlData,
			"abeginTime"=>$_POST['btime'],
			"aendTime"=>$_POST['endtime'],
			"activtype"=>$_POST['atype'],
			"atimes"=>$_POST['actimes']
		);
		//var_dump($val);
		$this->actioninfo_model->add_activ($val);
		echo"<script>alert('活动添加成功'); window.location='".site_url('/weixin/actioninfo')."';</script>";
	}
	
	//显示编辑页面
	function show_edit(){
		$activadd['alist']=$this->actioninfo_model->sel_one($this->aid);	
		$activadd['view']="action/actioninfo_manage_up_view";
		$activadd['id']=$this->aid;
		//var_dump($$this->actioninfo_model->sel_one($this->aid));
		$this->loadview($activadd,'xenon/common/index');
		
		
	}	
	//修改
	function edit_up(){
		$htmlData = '';
		if (!empty($_POST['content1'])) {
			if (get_magic_quotes_gpc()) { //这个函数打开会转义
				$htmlData = stripslashes($_POST['content1']);
			} else {
				$htmlData = $_POST['content1'];
			}
		}	
		$val=array(
			"addid"=>$this->adminid,
			"aname"=>$_POST['actxt'],
			"aword"=>$_POST['tkword'],
			"acont"=>$htmlData,
			"abeginTime"=>$_POST['btime'],
			"aendTime"=>$_POST['endtime'],
			"activtype"=>$_POST['atype'],
			"atimes"=>$_POST['actimes']
		);
		$this->actioninfo_model->update_one($this->aid,$val);
		echo"<script>alert('修改成功'); window.location='".site_url('/weixin/actioninfo')."';</script>";
	}
	
	//启用
	function is_uses(){
		$val1=array("isuse"=>'1');
		$this->actioninfo_model->update_one($this->aid,$val1);
		echo"<script>window.location='".site_url('/weixin/actioninfo')."';</script>";
	}
	
	//禁用
	function no_uses(){
		$val1=array("isuse"=>0);
		$this->actioninfo_model->update_one($this->aid,$val1);
		echo"<script>window.location='".site_url('/weixin/actioninfo')."';</script>";
	}
	
	//删除  连接得到ID，url的第三段
	function active_del(){
		$this->actioninfo_model->delete_one($this->aid);
		echo"<script>alert('删除成功'); window.location='".site_url('/weixin/actioninfo')."';</script>";
	}
	
}
?>